<template>
    <div class="orderhandle_detail">
        <Card>
            <p slot="title">
                物流订单详情
            </p>
            <div class="container">
                <!--物流单号-->
                <Row span="24" class="row-box">
                    <ul class="title-list">
                        <li>物流单号</li>
                        <li>{{adminTransportOrder.order_no}}</li>
                        <li>{{order_status[adminTransportOrder.order_status]}}</li>
                    </ul>
                    <ul class="content-list">
                        <li>
                            <span>始发地：</span>
                            <span class="atorder">{{adminTransportOrder.begin_province}}-</span><span class="atorder">{{adminTransportOrder.begin_city}}</span>
                        </li>
                        <li>
                            <span>目的地：</span>
                            <span class="atorder">{{adminTransportOrder.end_province}}-</span><span class="atorder">{{adminTransportOrder.end_city}}</span>
                        </li>
                        <li>
                            <span>发车日期：</span>
                            <span class="atorder">{{adminTransportOrder.begin_date}}</span>
                        </li>
                        <li>
                            <span>下单时间：</span>
                            <span class="atorder">{{adminTransportOrder.create_time}}</span>
                        </li>
                        <li>
                            <span>购车单号：</span>
                            <span class="atorder">{{adminTransportOrder.trade_order_id}}</span>
                        </li>
                        <li>
                            <span>企业名称：</span>
                            <span class="atorder">{{adminTransportOrder.party_name}}</span>
                        </li>
                        <li>
                            <span>企业类型：</span>
                            <span class="atorder">{{party_type[adminTransportOrder.partyType]}}</span>
                        </li>
                    </ul>
                </Row>
                <!--车辆信息-->
                <Row class="row-box">
                    <ul class="title-list">
                        <li>车辆信息</li>
                    </ul>
                    <Table border :columns="columns_info" :data="tableData_info"></Table>
                </Row>
                <!--车辆信息-提车收车信息-->
                <Row class="row-box">
                    <ul class="info-list">
                        <li>
                            <p class="info-title">提车信息</p>
                            <p>
                               <Checkbox  v-model="visit"></Checkbox>上门提车
                            </p>
                            <p>
                                <span>联系人:</span>
                                <span>{{sendPersonTransportAddress.user_name}}</span>
                            </p>
                            <p>
                                <span>联系电话:</span>
                                <span>{{sendPersonTransportAddress.user_phone}}</span>
                            </p>
                            <p>
                                <span>提车地址:</span>
                                <span>{{sendPersonTransportAddress.address}}</span>
                            </p>
                        </li>
                        <li>
                            <p class="info-title">送车信息</p>
                           <p>
                               <Checkbox v-model="car_door"></Checkbox>送车上门
                           </p>
                            <p>
                                <span>收车人:</span>
                                <span>{{receivePersonTransportAddress.user_name}}</span>
                            </p>
                            <p>
                                <span>联系电话:</span>
                                <span>{{receivePersonTransportAddress.user_phone}}</span>
                            </p>
                            <p>
                                <span>收车车地址:</span>
                                <span>{{receivePersonTransportAddress.address}}</span>
                            </p>
                            <p v-if="car_door">
                                <span>身份信息:</span>
                                <a style="text-decoration: underline" @click="write">填写</a>
                            </p>
                        </li>
                    </ul>
                </Row>
                <!--物流报价-->
                <Row class="row-box">
                    <ul class="title-list">
                        <li>物流报价</li>
                    </ul>
                    <Table  border :columns="columns_offer" :data="tableData_offer"></Table>
                </Row>
                <!--订单结算-->
                <Row class="row-box">
                   <ul class="title-list">
                       <li>订单结算</li>
                   </ul>
                   <p>
                       <span>结算金额:</span>
                       <a>{{settle_account }}</a>
                   </p>
                   <p>
                       <span>运车物流:</span>
                       <span>{{car_carrier}}</span>
                   </p>
                   <p>
                       <span>发票信息:</span>
                       <Checkbox v-model="need_invoice"></Checkbox>需要
                       <a v-if="invoice_info" style="text-decoration: underline" @click="inVoice_info">发票信息</a>
                   </p>
                   <p class="remark">
                       <span>备注说明:</span>
                       <textarea v-model="remark"></textarea>
                   </p>
               </Row>
                <!--取消、确定按钮-->
                <Row class="row-box">
                   <p class="detail-footer">
                       <Button class="detail-btn"  type="primary" @click="confirm">确定</Button >
                       <Button class="detail-btn" @click="cancel">取消</Button >
                   </p>
               </Row>
                <!--修改物流报价弹窗-->
                <modal ref="createApp" v-model="dialogAdd"  title="修改物流报价">
                      <Form class="step-form" ref="addApply" :model="addApply"  :label-width="100">
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="参考价：" prop="reference_price" label-position="left" :label-width="150">
                                    <Input  v-model="addApply.reference_price" type="text" style="width:220px" placeholder="请输入参考价" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="预估价：" prop="estimate_price" label-position="left" :label-width="150">
                                    <Input  v-model="addApply.estimate_price" type="text" style="width:220px"  placeholder="请输入预估价" />
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="实报价：" prop="real_price" label-position="left" :label-width="150">
                                    <Input  v-model="addApply.real_price" type="text" style="width:220px" placeholder="请输入实报价" />
                                </FormItem>
                            </i-col>
                        </Row>
                         <Row span="12">
                              <i-col span="12" >
                                  <FormItem label="预发时间：" prop="depart_time" label-position="left" :label-width="150">
                                      <Date-picker type="date"  v-model="addApply.depart_time"  placeholder="请输入预发时间" style="width: 220px"></Date-picker>
                                  </FormItem>
                              </i-col>
                         </Row>
                        <Row span="12">
                            <i-col span="12" >
                                <FormItem label="预到时间：" prop="arrive_time" label-position="left" :label-width="150">
                                    <Date-picker type="date"  v-model="addApply.arrive_time"  placeholder="请输入预到时间" style="width: 220px"></Date-picker>
                                </FormItem>
                            </i-col>
                        </Row>
                    </Form>
                    <div slot="footer">
                        <Button type="ghost"  @click="cancleSubmit()">取消</Button>
                        <Button type="primary"   @click="createSubmit()">保存</Button>
                    </div>
                </modal>
                <!--发票信息弹窗-->
                <modal ref="createApp" v-model="invoice_dialogAdd"  title="开具发票">
                    <Form class="orderhandle" style="max-height:300px;overflow: auto">
                        <FormItem label="发票类型：">
                            <Radio-group v-model="invoice_type" @on-change="changeModel">
                                <Radio label="0">普通发票</Radio>
                                <Radio label="1">增值税发票</Radio>
                            </Radio-group>
                        </FormItem>
                        <!--普通发票-->
                        <template v-if="invoice_type == 0">
                            <div class="form-input" v-bind:class="{'error':$v.invoice_title.$error}">
                                <div class="input">
                                    <span>发票抬头：</span><input type="text" value="" class="input-text" placeholder="填写单位名称全称（必填）" v-model.trim="invoice_title" @blur="$v.invoice_title.$touch()"/>
                                </div>
                                <div class="input-msg">
                                    <div class="msg">发票抬头不能为空</div>
                                </div>
                            </div>
                            <div class="form-input" v-bind:class="{'error':$v.duty_paragraph.$error}">
                                <div class="input">
                                    <span>税号：</span><input type="text" value="" class="input-text" placeholder="填写社会统一信用代码（必填）" v-model.trim="duty_paragraph" @blur="$v.duty_paragraph.$touch()"/>
                                </div>
                                <div class="input-msg">
                                    <div class="msg">税号不能为空</div>
                                </div>
                            </div>
                            <div class="form-input">
                                <div class="input">
                                    <span>单位地址：</span><input type="text" value="" class="input-text" placeholder="填写单位营业执照上注册的地址(普发可不填)" v-model.trim="unit_address"/>
                                </div>
                                <div class="input-msg"></div>
                            </div>
                            <div class="form-input">
                                <div class="input">
                                    <span>电话：</span><input type="text" value="" class="input-text" placeholder="填写税务登记的电话号码(普发可不填)" v-model.trim="phone"/>
                                </div>
                                <div class="input-msg"></div>
                            </div>
                            <div class="form-input">
                                <div class="input">
                                    <span>开户行：</span><input type="text" value="" class="input-text" placeholder="填写税务局开户的备案银行(普发可不填)" v-model.trim="opening_bank"/>
                                </div>
                                <div class="input-msg"></div>
                            </div>
                            <div class="form-input">
                                <div class="input">
                                    <span>银行账号：</span><input type="text" value="" class="input-text" placeholder="填写税务局开户的备案银行账号(普发可不填)" v-model.trim="bank_account"/>
                                </div>
                                <div class="input-msg"></div>
                            </div>
                        </template>
                        <!--增值税发票-->
                        <template v-if="invoice_type == 1">
                            <div class="form-input" v-bind:class="{'error':$v.invoicerule_title.$error}">
                                <div class="input">
                                    <span>发票抬头：</span><input type="text" value="" class="input-text" placeholder="填写单位名称全称（必填）" v-model.trim="invoicerule_title" @blur="$v.invoicerule_title.$touch()"/>
                                </div>
                                <div class="input-msg">
                                    <div class="msg">发票抬头不能为空</div>
                                </div>
                            </div>
                            <div class="form-input" v-bind:class="{'error':$v.dutyrule_paragraph.$error}">
                                <div class="input">
                                    <span>税号：</span><input type="text" value="" class="input-text" placeholder="填写社会统一信用代码（必填）" v-model.trim="dutyrule_paragraph" @blur="$v.dutyrule_paragraph.$touch()"/>
                                </div>
                                <div class="input-msg">
                                    <div class="msg">税号不能为空</div>
                                </div>
                            </div>
                            <div class="form-input" v-bind:class="{'error':$v.unitrule_address.$error}">
                                <div class="input">
                                    <span>单位地址：</span><input type="text" value="" class="input-text" placeholder="填写单位营业执照上注册的地址(必填)" v-model.trim="unitrule_address" @blur="$v.unitrule_address.$touch()"/>
                                </div>
                                <div class="input-msg">
                                    <div class="msg">单位地址不能为空</div>
                                </div>
                            </div>
                            <div class="form-input" v-bind:class="{'error':$v.phonerule.$error}">
                                <div class="input">
                                    <span>电话：</span><input type="text" value="" class="input-text" placeholder="填写税务登记的电话号码(普发可不填)" v-model.trim="phonerule" @blur="$v.phonerule.$touch()"/>
                                </div>
                                <div class="input-msg">
                                    <div class="msg">电话不能为空</div>
                                </div>
                            </div>
                            <div class="form-input" v-bind:class="{'error':$v.openingrule_bank.$error}">
                                <div class="input">
                                    <span>开户行：</span><input type="text" value="" class="input-text" placeholder="填写税务局开户的备案银行(必填)" v-model.trim="openingrule_bank" @blur="$v.openingrule_bank.$touch()"/>
                                </div>
                                <div class="input-msg">
                                    <div class="msg">开户行不能为空</div>
                                </div>
                            </div>
                            <div class="form-input" v-bind:class="{'error':$v.bankrule_account.$error}">
                                <div class="input">
                                    <span>银行账号：</span><input type="text" value="" class="input-text" placeholder="填写税务局开户的备案银行账号(必填)" v-model.trim="bankrule_account" @blur="$v.bankrule_account.$touch()"/>
                                </div>
                                <div class="input-msg">
                                    <div class="msg">银行账号不能为空</div>
                                </div>
                            </div>
                        </template>
                    </Form>
                    <div slot="footer">
                        <Button type="ghost" @click="inVoice_cancel">取消</Button>
                        <Button type="primary" @click="inVoice_save">保存</Button>
                    </div>
                </modal>
                <!--填写弹窗-->
                <modal ref="createApp" v-model="write_dialogAdd"  title="身份信息">
                    <Form ref="writeApply" :model="writeApply" :rules="writeruleValidate" style="max-height:300px;overflow: auto">
                        <Row span="16">
                            <i-col span="16" >
                              <FormItem label="身份证号：" prop="user_card" label-position="left" :label-width="100">
                                <Input type="text" placeholder="请输入身份证号" v-model="writeApply.user_card" style="width:220px"></Input>
                              </FormItem>
                            </i-col>
                        </Row>
                        <Row span="16">
                            <i-col span="16">
                                <FormItem label="身份证照片：" label-position="left"  :label-width="100">
                                    <Upload
                                            style="display: inline-block"
                                            :show-upload-list="false"
                                            :before-upload="handleUpload"
                                            action="//jsonplaceholder.typicode.com/posts/">
                                        <Button type="primary">上传</Button>
                                    </Upload>
                                </FormItem>
                            </i-col>
                        </Row>
                        <Row span="16">
                            <i-col span="16">
                                <FormItem  prop="uploadUrl" label-position="left"  :label-width="100">
                                    <img v-if="writeApply.uploadUrl !== ''"  :src="writeApply.uploadUrl" height="200" width="200">
                                </FormItem>
                            </i-col>
                        </Row>
                    </Form>
                    <div slot="footer">
                        <Button type="ghost" @click="cancelInfo('writeApply')">取消</Button>
                        <Button type="primary" @click="changeInfo('writeApply')">保存</Button>
                    </div>
                </modal>
                <!--确定弹窗1-->
                <Modal :title="title_info"  v-model="modaldialog">
                    <template v-if="modal_info == 2">
                        <h3>
                            <ul class="order-list">
                                <li>
                                    <span>{{adminTransportOrder.begin_province}}-</span><span>{{adminTransportOrder.begin_city}}</span>
                                    <p class="car_title">{{settle_account}}</p>
                                </li>
                                <li>
                                    <span>{{adminTransportOrder.end_province}}-</span><span>{{adminTransportOrder.end_city}}</span>
                                    <p class="car_money">{{car_carrier}}</p>
                                </li>
                            </ul>
                        </h3>
                        <div slot="footer">
                            <Button @click="cancel_info">取消</Button>
                            <Button type="primary" @click="confirm_info">确定</Button>
                        </div>
                    </template>
                    <template v-if="modal_info == 3">
                            <h3>物流配置成功，等待客户确认！</h3>
                            <div slot="footer">
                                <Button type="primary"  @click="close_info">关闭</Button>
                            </div>
                    </template>
                </Modal>
            </div>
        </Card>
    </div>
</template>

<script>
    import ajax from '../../../libs/axios.js'
    import TestModule from "../demo/components/layerModule";
    import {required} from 'vuelidate/lib/validators';
    import moment from 'moment';

    export default {
        name: 'orderhandle_detail',
        components: {TestModule},
        data () {
            return {
                title_info:"提示",
                modal_info:2,                    // 确定弹窗
                invoice_type:"0",                // 选择类型  普通发票 or 增值税发票
                order_info_id:"",
                settle_account:"",               // 结算金额
                car_carrier:"",                  // 运车物流
                remark:"",                       // 备注说明
                user_card:"",                    // 身份证号
                currentid:0,                     // 物流报价单选按钮
                visit:false,                     // 上门取车
                car_door:false,                  // 送车上门
                dialogAdd:false,                 // 修改弹窗是否显示
                modaldialog:false,               // 确定对话框
                need_invoice:false,              // 是否需要发票
                invoice_info:false,              // 发票信息是否显示
                invoice_dialogAdd:false,         // 发票弹窗是否显示
                write_dialogAdd:false,           // 填写身份信息

                needtake:0,                      // 是否需要上门提车
                needgive:0,                      // 是否需要送门上车
                needinvoice:0,                   // 是否需要发票

                invoice_title:"",                // 普通发票-抬头
                duty_paragraph:"",               // 普通发票-税号
                unit_address:"",                 // 普通发票-单位地址
                phone:"",                        // 普通发票-电话
                opening_bank:"",                 // 普通发票-开户行
                bank_account:"",                 // 普通发票-银行账号

                invoicerule_title:"",            // 增值税发票-抬头
                dutyrule_paragraph:"",           // 增值税发票-税号
                unitrule_address:"",             // 增值税发票-单位地址
                phonerule:"",                    // 增值税发票-电话
                openingrule_bank:"",             // 增值税发票-开户行
                bankrule_account:"",             // 增值税发票-银行账号

                addApply:{
                    reference_price:"",          // 参考价
                    estimate_price:"",           // 预估价
                    real_price:"",               // 实报价
                    depart_time:"",               // 预发时间
                    arrive_time:"",              // 预到时间
                    id:0,                        // 物流报价详情id
                },
                writeApply:{
                    user_card:"",                // 身份证号
                    uploadUrl:"",                // 上传图片路径
                },
                adminTransportOrder:{},          // 物流单号数据对象
                sendPersonTransportAddress:{     // 提车信息数据对象
                    user_name:"",
                    user_phone:"",
                    address:"",
                },
                receivePersonTransportAddress:{  // 收车信息数据对象
                    user_name:""
                },
                adminTransportInvoice:{},        //
                tableData_info:[],               // 车辆信息列表数据集合
                tableData_offer:[],              // 物流报价列表数据集合
                columns_info:[
                    {
                        title: '序号',
                        width:80,
                        align: 'center',
                        type: 'index'
                    },
                    {
                        title: '品牌车系',
                        align: 'center',
                        key: 'car_series'
                    },
                    {
                        title: '车型',
                        align: 'center',
                        key: 'car_size',
                    },
                    {
                        title: '状态',
                        align: 'center',
                        key: 'car_status',
                        render: (h, params) => {
                            if (params.row.can_drive === 0) {
                                return h('span', '不能')
                            }else if(params.row.can_drive === 1) {
                                return h('span', '能')
                            }
                        }
                    },
                    {
                        title: '估值(万元/辆)',
                        align: 'center',
                        key: 'valuation'
                    },
                    {
                        title: '台数',
                        align: 'center',
                        key: 'car_count'
                    },
                ],
                columns_offer:[
                    {
                        title: '选择',
                        key: 'chose',
                        width: 70,
                        align: 'center',
                        render: (h, params) => {
                            if(this.order_info_id){
                                this.addApply.id=this.order_info_id;
                                if (!this.settle_account){
                                    this.settle_account=params.row.final_price
                                }
                                if (!this.car_carrier){
                                    this.car_carrier=params.row.long_name
                                }
                            }
                            let id = params.row.id;
                            let flag = false;
                            if (this.currentid === id) {
                                flag = true
                            } else {
                                flag = false
                            }
                            let self = this
                            return h('div', [
                                h('Radio', {
                                    props: {
                                        value: flag
                                    },
                                    on: {
                                        'on-change': () => {
                                            self.currentid = id
                                            this.settle_account=params.row.final_price
                                            this.car_carrier=params.row.long_name
                                            this.addApply.id=id
                                        }
                                    }
                                })
                            ])
                        }
                    },
                    {
                        title: '物流',
                        align: 'center',
                        key: 'short_name',
                    },
                    {
                        title: '参考价',
                        align: 'center',
                        key: 'reference_price',
                    },
                    {
                        title: '预估价',
                        align: 'center',
                        key: 'all_cost',
                    },
                    {
                        title: '实报价',
                        align: 'center',
                        key: 'final_price'
                    },
                    {
                        title: '预到时间',
                        align: 'center',
                        key: 'arrive_time'
                    },
                    {
                        title: '操作',
                        key: 'action',
                        width: 180,
                        align: 'center',
                        render: (h, params) => {
                            return h('div', [
                                h(
                                    'Button',
                                    {
                                        props: {
                                            type: 'info',
                                            size: 'small'
                                        },
                                        style: {
                                            marginRight:'5px',
                                        },
                                        on: {
                                            click: () => {
                                                this.editData(params.row)
                                            }
                                        }
                                    },
                                    '修改'
                                ),
                            ])
                        }
                    }

                ],
                order_status:{"-1":"已取消","1":"待报价","2":"待确认","3":"待安排","4":"待发运","5":"运输中","6":"待收车","7":"已完成"},  // 订单状态
                party_type:{"1":"2P","2":"4S","3":"质押监管员","4":"2B","5":"小b","6":"个人"},   // 公司类型
                // 填写身份信息表单验证
                writeruleValidate:{
                    user_card:[
                        { required: true, message: '身份证号不能为空', trigger: 'blur' },
                        { type: 'string',pattern:/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message:'请输入正确的身份证号', trigger:'blur'},
                    ],
                },
            }
        },
        // 验证
        validations:{
            // 普通发票验证
            invoice_title:{required},
            duty_paragraph:{required},

            // 增值税发票验证
            invoicerule_title:{required},
            dutyrule_paragraph:{required},
            unitrule_address:{required},
            phonerule:{required},
            openingrule_bank:{required},
            bankrule_account:{required}
        },
        created () {
            this.init();
        },
        activated: function () {
            this.init()
        },
        methods: {
            // 数据初始化
            init () {
                this.$store.commit('setActiveName', 'orderhandleindex')
                this.getlist();
            },
            // 获取列表
            getlist(){
                let url="adminlogin/transportOrder/selectTransportById";
                let data = {
                    id:this.$route.params.id
                }
                ajax.formRes(url, data).then(res => {
                    this.adminTransportOrder=res.data.adminTransportOrder;
                    this.remark=res.data.adminTransportOrder.remark;
                    this.tableData_info=res.data.adminTransportOrderCarList;
                    this.sendPersonTransportAddress=res.data.sendPersonTransportAddress;
                    this.receivePersonTransportAddress=res.data.receivePersonTransportAddress;
                    this.tableData_offer=res.data.adminTransportOrderInfoList;

                    // 是否需要发票
                    if (res.data.adminTransportOrder.need_invoice  == 1){
                        this.need_invoice=true;
                        this.needinvoice=1;
                    }else if (res.data.adminTransportOrder.need_invoice  == 0){
                        this.need_invoice=false;
                        this.needinvoice=0;
                    }

                    // 发票信息
                    this.adminTransportInvoice=res.data.adminTransportInvoice;
                    if (res.data.adminTransportInvoice.invoice_type == ''){
                        this.invoice_type=""
                    }else{
                        this.invoice_type=res.data.adminTransportInvoice.invoice_type.toString();
                    }
                    this.duty_paragraph=res.data.adminTransportInvoice.taxpayer_no;
                    this.unit_address=res.data.adminTransportInvoice.cust_addr;
                    this.phone=res.data.adminTransportInvoice.cust_phone;
                    this.opening_bank=res.data.adminTransportInvoice.depositBank;
                    this.bank_account=res.data.adminTransportInvoice.account;
                    this.invoice_title=res.data.adminTransportInvoice.cust_name;

                    if (res.data.adminTransportOrder.need_take  == 1){
                        this.visit=true;
                        this.needtake=1;
                    }else if (res.data.adminTransportOrder.need_take  == 0){
                        this.visit=false;
                        this.needtake=0;
                    }
                    if (res.data.adminTransportOrder.need_give  == 1){
                        this.car_door=true;
                        this.needgive=1;
                    }else if (res.data.adminTransportOrder.need_give  == 0){
                        this.car_door=false;
                        this.needgive=0;
                    }


                    this.order_info_id=res.data.adminTransportOrder.order_info_id;
                    this.addApply.id=this.order_info_id;
                    if (!res.data.adminTransportOrder.order_info_id){
                        this.currentid=0;
                    }else{
                        this.currentid=res.data.adminTransportOrder.order_info_id;
                    }
                }).catch(err => {
                    console.log('有错误信息')
                })
            },
            // 物流报价修改
            editData(row){
                this.dialogAdd=true;
                this.addApply.reference_price=row.reference_price,  // 参考价
                this.addApply.estimate_price=row.all_cost,          // 预估价
                this.addApply.real_price=row.final_price            // 实报价
                this.addApply.arrive_time=row.arrive_time           // 预到时间
                this.addApply.depart_time=row.depart_time           // 预发时间
                this.addApply.id=row.id                             // 详情id
            },
            // 修改物流报价弹窗取消
            cancleSubmit(name){
                this.dialogAdd=false;  // 取消关闭弹窗
            },
            // 修改物流报价弹窗保存
            createSubmit(name){
                let url="adminlogin/transport/updateTransportPrice";
                let data = {
                    operator_id:localStorage.getItem('userId'),
                    order_info_id:this.addApply.id,
                    all_cost:this.addApply.estimate_price,
                    final_price:this.addApply.real_price,
                    reference_price:this.addApply.reference_price,
                    arrive_time:moment(this.addApply.arrive_time).format('YYYY-MM-DD'),
                    depart_time:moment(this.addApply.begin_time).format('YYYY-MM-DD')
                }
                ajax.formRes(url, data).then(res => {
                    if (res.code == 200){
                        this.$Message.success('修改成功');
                        this.dialogAdd=false;  // 关闭弹窗
                        this.settle_account=this.addApply.real_price;
                    }
                }).catch((err)=>{
                    console.log('有错误信息')
              })
            },
            // 发票弹窗取消按钮
            inVoice_cancel(name){
                this.invoice_dialogAdd=false;  // 取消关闭弹窗
            },
            // 发票弹窗保存
            inVoice_save(name){
                let obj={};
                if (this.invoice_type == 0){
                    this.$v.invoice_title.$touch();
                    this.$v.duty_paragraph.$touch();
                    obj['id']=this.adminTransportInvoice.id;
                    obj['invoice_type']=this.invoice_type;
                    obj['taxpayer_no']=this.duty_paragraph;
                    obj['cust_addr']=this.unit_address;
                    obj['cust_phone']=this.phone;
                    obj['depositBank']=this.opening_bank;
                    obj['account']=this.bank_account;
                    obj['cust_name']=this.invoice_title;
                    if(!this.$v.invoice_title.$error && !this.$v.duty_paragraph.$error) {
                        this.inVoice_submit(obj);
                    }
                }else if (this.invoice_type == 1){
                    this.$v.invoicerule_title.$touch();
                    this.$v.dutyrule_paragraph.$touch();
                    this.$v.unitrule_address.$touch();
                    this.$v.phonerule.$touch();
                    this.$v.openingrule_bank.$touch();
                    this.$v.bankrule_account.$touch();
                    obj['id']=this.adminTransportInvoice.id;
                    obj['invoice_type']=this.invoice_type;
                    obj['taxpayer_no']=this.dutyrule_paragraph;
                    obj['cust_addr']=this.unitrule_address;
                    obj['cust_phone']=this.phonerule;
                    obj['depositBank']=this.openingrule_bank;
                    obj['account']=this.bankrule_account;
                    obj['cust_name']=this.invoicerule_title;
                    if(!this.$v.invoicerule_title.$error && !this.$v.dutyrule_paragraph.$error && !this.$v.unitrule_address.$error && !this.$v.phonerule.$error && !this.$v.openingrule_bank.$error && !this.$v.bankrule_account.$error) {
                        this.inVoice_submit(obj);
                    }
                }
            },
            // 普通发票 && 增值税发票调用
            inVoice_submit(obj){
                let url="adminlogin/transport/updateAdminTransportInvoice";
                let data = {
                    user_id:localStorage.getItem('userId'),
                    order_id:this.$route.params.id,
                    invoice:JSON.stringify(obj)
                }
                ajax.formRes(url, data).then(res => {
                    if (res.info.code == 200){
                        this.$Message.success('修改成功');
                        this.invoice_dialogAdd=false;     // 关闭弹窗
                        this.getlist();
                    }
                }).catch((err)=>{
                    console.log('有错误信息');
                })
            },
            // 上传文件
            handleUpload (file) {
                this.file = file
                this.upload();
                return false;
            },
            // 上传图片
            upload (type) {
                let _this = this
                let fileName = _this.file.name
                //FormData 对象
                let formData = new FormData()
                // 文件对象
                formData.append("img", _this.file)
                formData.append("type", "partyInfo")
                ajax.upload('adminlogin/file/uploadOssImage',formData).then(function (res) {
                    setTimeout(() => {
                        _this.writeApply.uploadUrl = res.url;
                        _this.file = '';
                        _this.$Message.success('上传成功');
                    }, 500);
                }, function (err) {
                    console.log(err)
                }).catch(function (error) {
                    console.log(error)
                })
            },
            // 物流订单处理详情取消
            cancel(){
                this.$router.push({name: 'orderhandleindex',})
            },
            // 发票信息
            inVoice_info(){
              this.invoice_dialogAdd=true;
              if (this.adminTransportInvoice == undefined){
                  this.invoice_type="0";
                  this.duty_paragraph="";
                  this.unit_address="";
                  this.phone="";
                  this.opening_bank="";
                  this.bank_account="";
                  this.invoice_title="";
                  this.dutyrule_paragraph="";
                  this.unitrule_address="";
                  this.phonerule="";
                  this.openingrule_bank="";
                  this.bankrule_account="";
                  this.invoicerule_title="";
              }else{
                  if (this.adminTransportInvoice.invoice_type == '' || this.adminTransportInvoice.invoice_type == undefined){
                      this.invoice_type="0";
                  }else{
                      this.invoice_type=this.adminTransportInvoice.invoice_type.toString();
                  }

                  if (this.invoice_type == '0'){
                      this.duty_paragraph=this.adminTransportInvoice.taxpayer_no;
                      this.unit_address=this.adminTransportInvoice.cust_addr;
                      this.phone=this.adminTransportInvoice.cust_phone;
                      this.opening_bank=this.adminTransportInvoice.depositBank;
                      this.bank_account=this.adminTransportInvoice.account;
                      this.invoice_title=this.adminTransportInvoice.cust_name;
                  }else if(this.invoice_type == '1'){
                      this.dutyrule_paragraph=this.adminTransportInvoice.taxpayer_no;
                      this.unitrule_address=this.adminTransportInvoice.cust_addr;
                      this.phonerule=this.adminTransportInvoice.cust_phone;
                      this.openingrule_bank=this.adminTransportInvoice.depositBank;
                      this.bankrule_account=this.adminTransportInvoice.account;
                      this.invoicerule_title=this.adminTransportInvoice.cust_name;
                  }
              }
            },
            // 切换发票信息
            changeModel(newval){
                this.invoice_type=newval;
            },
            // 填写弹窗
            write(){
                this.write_dialogAdd=true;
            },
            // 送车信息-身份信息填写取消
            cancelInfo(name){
                this.write_dialogAdd=false;  // 取消关闭弹窗
                this.$refs[name].resetFields();
            },
            // 送车信息-身份信息填写保存
            changeInfo(name){
                this.$refs[name].validate((valid) => {
                    if (valid) {
                        let url ="adminlogin/transport/updateAdminTransportAddress";
                        let data = {
                            user_id:localStorage.getItem('userId'),
                            order_id:this.$route.params.id,
                            receive_person_id:this.receivePersonTransportAddress.id,
                            user_card:this.writeApply.user_card,
                            card_image:this.writeApply.uploadUrl,
                        }
                        ajax.formRes(url, data).then(res => {
                            if (res.info.code == 200){
                                this.$Message.success('修改成功');
                                this.write_dialogAdd=false;    // 关闭弹窗
                                this.$refs[name].resetFields();
                            }
                        }).catch((err)=>{
                            console.log('有错误信息')
                        })
                    }
                });
            },
            // 详情页面确认按钮
            confirm(){
                if (!this.addApply.id){
                    this.$Message.info('请选择物流报价');
                }else{
                    this.modaldialog=true;
                    this.modal_info=2;
                    this.title_info='物流订单配置信息';
                }
            },
            // 物流配置第二步取消按钮
            cancel_info(){
                this.modaldialog=false;
            },
            // 物流配置第二步确认按钮
            confirm_info(){
                let url='adminlogin/transport/storageOrConfirmTransportOrder';
                let data={
                    user_id:localStorage.getItem('userId'),
                    order_id:this.$route.params.id,
                    order_info_id:this.addApply.id,
                    need_take:this.needtake,
                    need_give:this.needgive,
                    need_invoice:this.needinvoice
                }
                ajax.formRes(url, data).then(res => {
                    if (res.info.code == 200){
                        this.modal_info=3;
                        this.title_info='物流配置成功';
                    }
                }).catch((err)=>{
                    console.log('有错误信息')
                })
            },
            // 物流配置成功后关闭按钮
            close_info(){
                this.modaldialog=false;
                this.$router.push({
                    name:"orderhandleindex"
                })
            }
        },
        watch:{
            need_invoice(newVal,oldVal){
               if (newVal){
                 this.invoice_info=true;
                 this.needinvoice=1;
               }else{
                   this.invoice_info=false;
                   this.needinvoice=0;
               }
            },
            car_door(newVal,oldVal){
                if (newVal){
                    this.needgive=1;
                }else{
                    this.needgive=0;
                }
            },
            visit(newVal,oldVal) {
                if (newVal) {
                    this.needtake = 1;
                } else {
                    this.needtake = 0;
                }
            }
        },
    }
</script>


<style lang="less">
    @import "./less/common";
</style>
<style>
    @import "../../../styles/css/vuelidate.css";
    .orderhandle  .ivu-form .ivu-form-item-label{
        width: 82px;
    }
    .car_title{
        font-size:18px;
        color: #2d8cf0;
        font-weight: bold;
    }
    .car_money{
        font-size:18px;
        color: #ff0000;
        font-weight: bold;
    }
     .order-list{
       height: 100px;
    }
     .order-list li{
        width: 40%;
        float: left;
        text-align: center;
    }
</style>
<style scoped>
    .form-input .msg{
        margin-left: 120px;
    }
</style>


